/**
 * 
 */
package com.csc.bankingsystem.web.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import com.csc.bankingsystem.core.util.ConstantManager;
import com.csc.bankingsystem.web.exception.BSAPIResponseException;

/**
 * @author angelkid
 *
 */
public class BSDateTimeUtil {
	public static Date parseDateFromString(String datetimeStr, String pattern){
		if(StringUtils.isEmpty(datetimeStr) || StringUtils.isEmpty(pattern)){
			return null;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		sdf.setLenient(false);
		try {
			return sdf.parse(datetimeStr);
		} catch (ParseException e) {
			throw new BSAPIResponseException(ConstantManager.INVALID_DATE, "Invalid date");
		}
	}
}
